package com.ruoyi.web.controller.combat.socialmedia;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.combat.domain.userlocation.CombatRelation;
import com.ruoyi.combat.service.userlocation.ICombatRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户社交关系Controller
 *
 * @author ruoyi
 * @date 2024-08-30
 */
@Api(tags = "课题三、课题五：网络抗定位、抗关联-社交关系管理")
@RestController
@RequestMapping("/userlocation/relation")
public class CombatRelationController extends BaseController {
    @Autowired
    private ICombatRelationService combatRelationService;

    /**
     * 查询用户社交关系列表
     */
    @ApiOperation(value = "查询用户社交关系列表")
    @PreAuthorize("@ss.hasPermi('system:relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombatRelation combatRelation) {
        startPage();
        List<CombatRelation> list = combatRelationService.selectCombatRelationList(combatRelation);
        return getDataTable(list);
    }

    /**
     * 导出用户社交关系列表
     */
    @ApiOperation(value = "导出用户社交关系列表")
    @PreAuthorize("@ss.hasPermi('system:relation:export')")
    @Log(title = "用户社交关系 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatRelation combatRelation) {
        List<CombatRelation> list = combatRelationService.selectCombatRelationList(combatRelation);
        ExcelUtil<CombatRelation> util = new ExcelUtil<CombatRelation>(CombatRelation.class);
        util.exportExcel(response, list, "用户社交关系数据");
    }

    /**
     * 获取用户社交关系详细信息
     */
    @ApiOperation(value = "获取用户社交关系详细信息")
    @PreAuthorize("@ss.hasPermi('system:relation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(combatRelationService.selectCombatRelationById(id));
    }

    /**
     * 新增用户社交关系
     */
    @ApiOperation(value = "新增用户社交关系")
    @PreAuthorize("@ss.hasPermi('system:relation:add')")
    @Log(title = "用户社交关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombatRelation combatRelation) {
        return toAjax(combatRelationService.insertCombatRelation(combatRelation));
    }

    /**
     * 修改用户社交关系
     */
    @ApiOperation(value = "修改用户社交关系")
    @PreAuthorize("@ss.hasPermi('system:relation:edit')")
    @Log(title = "用户社交关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CombatRelation combatRelation) {
        return toAjax(combatRelationService.updateCombatRelation(combatRelation));
    }

    /**
     * 删除用户社交关系
     */
    @ApiOperation(value = "删除用户社交关系")
    @PreAuthorize("@ss.hasPermi('system:relation:remove')")
    @Log(title = "用户社交关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(combatRelationService.deleteCombatRelationByIds(ids));
    }

    /**
     * 查询用户的关注/粉丝
     */
    @ApiOperation(value = "查询用户社交关系列表")
    @PreAuthorize("@ss.hasPermi('system:relation:list')")
    @GetMapping("/user/{userId}")
    public TableDataInfo list(@PathVariable String userId, @RequestParam(required = false) String plate,
                              @RequestParam(required = false) String relation) {
        startPage();
        CombatRelation combatRelation = new CombatRelation(null, userId, null, relation, null, plate);
        List<CombatRelation> list = combatRelationService.selectRelationByUserId(combatRelation);
        return getDataTable(list);
    }

    /**
     * 查询用户的关注/粉丝
     */
    @ApiOperation(value = "查询用户的双层社交关系列表")
    @PreAuthorize("@ss.hasPermi('system:relation:list')")
    @GetMapping("/graph/{userId}")
    public AjaxResult getGraph(@PathVariable String userId) {
        return AjaxResult.success(combatRelationService.getGraphRelation(userId));
    }

}
